package com.example.demo.mapper;

import com.example.demo.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper {
    @Select("select * from user order by Power desc")
    List<User> selectUser();

    @Select("select PassWord from user where CustomerId=#{id}")
    String selectById(String id);

    @Select("select * from user where CustomerId=#{id}")
    User selectById1(String id);

    @Insert("insert into user(CustomerId,PassWord,UserName,PhoneNumber,Address,Balance,Power) values(#{CustomerId},#{PassWord},#{UserName},#{PhoneNumber},#{Address},#{Balance},#{Power})")
    void insertUser(User user);

    @Select("select Balance from user where CustomerId=#{id}")
    String selectBalance(String id);

    @Update("update user set Balance=Balance-#{money} where CustomerId=#{id}")
    void updateBalance(String money,String id);

    @Update("update user set Balance=Balance+#{money} where CustomerId=#{id}")
    void updateBalance1(String money,String id);

    @Update("update user set PassWord=#{pw} where CustomerId=#{id}")
    void updatePw(String pw,String id);

    @Select("select Power from user where CustomerId=#{id}")
    int selectPower(String id);

    @Update("update user set PassWord=#{PassWord},UserName=#{UserName},PhoneNumber=#{PhoneNumber},Address=#{Address},Balance=#{Balance},Power=#{Power} where CustomerId=#{CustomerId}")
    void updateUser(User user);

    @Delete("delete from user where CustomerId=#{id}")
    void delUser(String id);

    @Insert("insert into user(CustomerId,PassWord,UserName,PhoneNumber,Address,Balance,Power) values(#{CustomerId},#{PassWord},#{UserName},#{PhoneNumber},#{Address},#{Balance},#{Power})")
    void addUser(User user);

    @Update("update user set UserName=#{UserName},PhoneNumber=#{PhoneNumber},Address=#{Address} where CustomerId=#{CustomerId}")
    void updateUserInfo(User user);
}
